<?php

namespace App\Http\Controllers\backend;

use App\Models\Operation;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Input;

class OperationController extends BaseController {
	
	public function index() {
		$operations = Operation::select(['action', 'content', 'created_at']);
		if(Input::get('action')) {
			$operations = $operations->where('action', 'like', '%'.Input::get('action').'%');
		}
		if(Input::get('content')) {
			$operations = $operations->where('content', 'like', '%'.Input::get('content').'%');
		}
		$operations = $operations->orderBy('id', 'desc')->paginate(50);
		return view('backend.operations', compact('operations'));
	}
	
	public function destroyAll() {
		Operation::query()->truncate();
			Operation::create([
				'action' => '清空记录',
				'content' => '清空操作记录成功',
			]);
		return Redirect::to('/backend/operations');
	}
}
